<script setup>
import {reactive} from "vue";
import {requestAllWares, requestGetInfo} from "@/api";
const routerGroup = reactive({
  linkIndex() {
    uni.redirectTo({url: "../index/index"});
  },
  linkOrder() {
    uni.redirectTo({url: "../order/order"});
  },
  linkUser() {
    uni.redirectTo({url: "../user/user"});
  },
  linkShop() {
    uni.navigateTo({url: "../shop/shop"})
  },
  linkLogin(){
    uni.navigateTo({url:"../login/login"})
  },
  linkUserInfo(){
    uni.navigateTo({url:"../userInfo/userInfo"});
  }
})
const swiper = reactive({
  //指示器
  indicatorDots: true,
  //自动播放
  autoplay: true,
  //时间，单位毫秒
  interval: 3000,
  //移动速度
  duration: 500,
})

const storageGroup = reactive({
  userinfo:uni.getStorageSync("userInfo"),
  initUsername(){
    if (this.userinfo.login_state){
      userInfoGroup.getUserInfo(this.userinfo.account);
    }
  }
})

const userInfoGroup = reactive({
  username:"",
  async getUserInfo(account){
    let result = await requestGetInfo({account:account})
    if (result.statusCode === 200){
      this.username = result.data[0].username;
    }
  }
})

storageGroup.initUsername();
</script>

<template>
  <view class="index-page">
    <scroll-view scroll-y="true">
      <view class="container-box">
        <view class="top-swiper">
          <van-row>
            <view class="uni-margin-wrap">
              <swiper :autoplay="swiper.autoplay" :duration="swiper.duration" :indicator-dots="swiper.indicatorDots"
                      :interval="swiper.interval" circular
                      class="swiper">
                <swiper-item>
                  <view class="swiper-item"><img alt="" class="swiper-img" src="http://118.178.254.102:1253/%E8%81%94%E6%83%B3%E6%8B%AF%E6%95%91%E8%80%85%20Y9000P-1.png"></view>
                </swiper-item>
                <swiper-item>
                  <view class="swiper-item"><img alt="" class="swiper-img" src="http://118.178.254.102:1253/ECM-S1-4.png"></view>
                </swiper-item>
                <swiper-item>
                  <view class="swiper-item"><img alt="" class="swiper-img" src="http://118.178.254.102:1253/DSC-RX1RM2-1.png"></view>
                </swiper-item>
                <swiper-item>
                  <view class="swiper-item"><img alt="" class="swiper-img" src="http://118.178.254.102:1253/Alpha%207CR-2.png"></view>
                </swiper-item>
                <swiper-item>
                  <view class="swiper-item"><img alt="" class="swiper-img" src="http://118.178.254.102:1253/Xperia%201%20V%20-2.png"></view>
                </swiper-item>
              </swiper>
            </view>
          </van-row>
        </view>
        <view class="top">
          <van-row>
            <van-col span="12">
              <van-image
                  round
                  width="100rpx"
                  height="100rpx;"
                  src="http://118.178.254.102:1251/user/head.jpg"
              />
            </van-col>
            <van-col span="12">
              <view class="top-text-box">
                <text class="top-text" v-if="!storageGroup.userinfo.login_state" @click="routerGroup.linkLogin()">登录/注册</text>
                <text class="top-text" v-if="storageGroup.userinfo.login_state" @click="routerGroup.linkUserInfo()">{{userInfoGroup.username}}</text>
              </view>
            </van-col>
          </van-row>
        </view>
        <view class="main-box">
          <van-row>
            <van-col span="16">
              <view class="main-title-box">
                <text class="main-title">HellShop特惠</text>
              </view>
            </van-col>
            <van-col span="8">
              <view class="main-btn-box">
                <button class="main-btn" @click="routerGroup.linkShop()">进入商城</button>
              </view>
            </van-col>
          </van-row>
        </view>
        <view class="bottom-box">
          <img alt="" class="bottom-box-img" src="http://118.178.254.102:1253/ThinkPad X1-1.png">
        </view>
        <view class="message"></view>
      </view>
      <van-row>
        <van-tabbar>
          <van-tabbar-item icon="home-o" @click="routerGroup.linkIndex">首页</van-tabbar-item>
          <van-tabbar-item icon="search" @click="routerGroup.linkOrder">订单</van-tabbar-item>
          <van-tabbar-item icon="friends-o" @click="routerGroup.linkUser">我的</van-tabbar-item>
        </van-tabbar>
      </van-row>
    </scroll-view>
  </view>
</template>

<style scoped src="../../css/index.css">

</style>
